package com.lhf.springcloud.DAO;

import com.lhf.springcloud.Entity.StudentBasicInfo;
import com.lhf.springcloud.Entity.StudentInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface StudentBasicDao {
    @Insert("insert into student_basic_info (id,studentName,idCard,grade,studentBirthday,entrance,studentXJ,studentRegistrationNo) values((select uuid()),#{studentName},#{idCard},#{grade},#{studentBirthday},#{entrance},#{studentXJ},#{studentRegistrationNo})")
    void addCourse(StudentBasicInfo course);
    @Select({"<script>","select SQL_CALC_FOUND_ROWS 1,id,studentName,idCard,studentBirthday,entrance,studentXJ,studentRegistrationNo from student_basic_info where 1=1",
            "<when test='idCard!=null'>",
            "AND idCard = #{idCard}",
            "</when>",
            "<when test='teacherName!=null'>",
            "AND studentName = #{teacherName}",
            "</when>"
            ,"limit #{startPage},#{endPage}",
            "</script>"})
    List<StudentBasicInfo> findAllStudentBasicData(Integer startPage,Integer endPage,String idCard,String teacherName);
    @Select("select FOUND_ROWS()")
    Integer findCount();
    @Select("select idCard from student_basic_info where idCard=#{idCard}")
    String findStudentBasicDataByIdCard(String idCard);
    @Update("UPDATE student_basic_info SET ${dataName} = #{dataValue} WHERE id = #{id} ")
    void updateData(String dataValue, String id, String dataName);
    @Select("select * from student_basic_info where idCard=#{idCard}")
    List<StudentBasicInfo> findByIdCard(String idCard);
}
